package org.erepublik.company;

import java.util.HashMap;

/**
 * Enum reprezentujacy wszystkie produkty dostepne w erepublik
 * 
 * @author Kacper Gorski 'Railman' railman85@gmail.com
 */
public enum EProductType {

    FOOD(false, 1, "Food", "food", 6), 
    RIFLE(false, 6, "Rifle", "rifle", 60), 
    HELICOPTER(false, 9, "Air Unit", "helicopter", 60), 
    TANK(false, 7, "Tank", "tank", 60), 
    ARTILLERY(false, 8, "Artillery", "artillery", 60), 
    TICKET(false, 2, "Moving Tickets", "ticket", 60), 
    HOUSE(false, 3, "House", "house", 750), 
    DEFENSE_SYSTEM(false, 5, "Defense System", "ds", 3450), 
    HOSPITAL(false, 4, "Hospital", "hospital", 3450), 
    STONE(true, 13, "Stone", "stone", 1), 
    OIL(true, 11, "Oil", "oil", 1), 
    GRAIN(true, 10, "Grain", "grain", 1), 
    TITANIUM(true, 12, "Titanium", "titanium", 1), 
    IRON(true, 14, "Iron", "iron", 1);

    private boolean isRaw;
    private int erepublikId;
    private int rawRequired;
    private String name;
    private String simpleName;
    private static HashMap<String, EProductType> map2 = null;
    private static HashMap<String, EProductType> map = null;

    /**
     * 
     * @param isRaw
     *            - czy produkt jest rawem (surowcem)
     * @param erepiblikId
     *            - id produktu na stronie erepublik
     * @param name
     *            - nazwa produktu
     */
    EProductType(boolean isRaw, int erepiblikId, String name, String simpleName, int rawRequired) {
        this.isRaw = isRaw;
        this.erepublikId = erepiblikId;
        this.name = name;
        this.simpleName = simpleName;
        this.rawRequired = rawRequired;
    }

    /**
     * @return true, jesli produkt jest surowcem, false w p.p.
     */
    public boolean isRaw() {
        return isRaw;
    }

    public int getErepublikId() {
        return erepublikId;
    }

    public String getName() {
        return name;
    }
    
    public int getRawRequired() {
        return rawRequired;
    }

    public static EProductType getProductTypeByName(String name) {
        if (map == null)
            initMap();
        return map.get(name);
    }

    public static EProductType getProductTypeBySimpleName(String name) {
        if (map2 == null)
            initMap();
        return map2.get(name);
    }

    private static void initMap() {
        map = new HashMap<String, EProductType>();
        for (EProductType product : EProductType.values()) {
            map.put(product.getName(), product);
        }
        map2 = new HashMap<String, EProductType>();
        for (EProductType product : EProductType.values()) {
            map2.put(product.getSimpleName(), product);
        }
    }

    public String getSimpleName() {
        return simpleName;
    }
}
